<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta charset="utf-8">
		<title>添加后台用户</title>
		<link rel="stylesheet" href="../layui/css/layui.css" />
		<style type="text/css">
			.addadminuser-con {
				padding: 0 15px 15px 15px;
				margin-bottom: 40px;
			}
			
			.addadminuser-con .top-inp {
				margin-left: 20px;
			}
			
			.addadminuser-con .from-con {
				margin: auto;
				background-color: #E2E2E2;
				padding: 10px;
				overflow: hidden;
			}
			
			.addadminuser-con .from-con .layui-form-item {
				margin: 20px 0;
			}
			
			.addadminuser-con .not_border_left {
				border-left: none !important;
			}
			
			.addadminuser-con .layui-form-item .layui-input-block .required {
				color: #ffb800;
				font-size: 32px;
				float: left;
				margin-left: 5px;
				margin-top: 5px;
				position: absolute;
				right: -15px;
			}
			
			.addadminuser-con .layui-form-select dl dd.layui-this {
				background-color: #1E9FFF !important;
			}
			
			.addadminuser-con .layui-btn {
				background-color: #1E9FFF !important;
			}
			
			.addadminuser-con .layui-form-select dl {
				max-height: 230px !important;
			}
			
			.addadminuser-con .layui-form-item {
				margin-bottom: 30px !important;
			}
		</style>
	</head>

	<body>
		<div class="addadminuser-con">
			<div class="from-con">
				<div style="width: 80%;">
					<form class="layui-form" action="" id="addadminuser">
						<div class="layui-form-item">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-block">
								<input id="adminusername" type="text" style="float: left;position: relative;" name="adminusername" lay-verify="required" placeholder="请输入用户名" class="layui-input" autocomplete="off">
								<i class="required">*</i>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码</label>
							<div class="layui-input-block">
								<input id="password" type="password" style="float: left;position: relative;" name="password" lay-verify="required" placeholder="请输入密码" class="layui-input" autocomplete="off">
								<i class="required">*</i>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">确认密码</label>
							<div class="layui-input-block">
								<input id="confirmpassword" type="password" style="float: left;position: relative;" name="confirmpassword" lay-verify="confirmPwd" placeholder="请输入确认密码" class="layui-input" autocomplete="off">
								<i class="required">*</i>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">真实姓名</label>
							<div class="layui-input-block">
								<input id="adminrealname" name="adminrealname" type="text" style="float: left;position: relative;" class="layui-input" placeholder="请输入真实姓名" lay-verify="required" autocomplete="off">
								<i class="required">*</i>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">角色</label>
							<div class="layui-input-block">
								<select name="backrolemodel" id="backrolemodel" lay-filter="backrolemodel">
									<option value="00">请选择角色</option>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">联系电话</label>
							<div class="layui-input-block">
								<input id="phone" name="phone" type="tel" style="float: left;position: relative;" class="layui-input" placeholder="请输入联系电话" lay-verify="required|phone" autocomplete="off">
								<i class="required">*</i>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button type="button" id="btnaddadminuser" lay-submit="" lay-filter="btnaddadminuser" class="layui-btn" style="float: right;"> 保  存 </button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="../js/jquery-3.3.1.js"></script>
		<script src="../layui/layui.all.js"></script>
		<!-- 以下2019-1-7徐震霖添加 -->
		<script src="../lib/md5.js"></script>
		<script src="../lib/Constant.js"></script>
		<script type="text/javascript">
			layui.use(['form'], function() {
				var form = layui.form;

				//判断两次输入密码一致
				form.verify({
					confirmPwd: function(value, item) {
						if(!new RegExp($("#password").val()).test(value)) {
							return "两次输入密码不一致，请重新输入！";
						}
					}
				});

				/**
				 * 2019-1-7徐震霖修改添加
				 */
				$("#confirmpassword").hover(function() {
					//alert("111")
					layer.tips('密码是由英文字符、数字、下划线组成的6-18位的字符串！', $(this), {
						tips: [2, '#1E9FFF'],
						time: 4000
					});
				});

				/**
				 * 2019-1-7徐震霖修改添加
				 */
				$("#password").hover(function() {
					//alert("111")
					layer.tips('密码是由英文字符、数字、下划线组成的6-18位的字符串！', $(this), {
						tips: [2, '#1E9FFF'],
						time: 4000
					});
				});

				//加载角色类型
				$.ajax({
					type: 'get',
					url: '../sysbackmanage/getallbackrolelist',
					datatype: 'json',
					success: function(roledata) {
						if(roledata.code == 0) {
							var str = "";
							for(var i = 0; i < roledata.count; i++) {
								str += '<option value=' + roledata.data[i].id + '>' + roledata.data[i].name + '</option>';
							}
							$("#backrolemodel").append(str);
							form.render();
						} else {
							layer.msg("角色信息获取失败");
						}
					},
					error: function() {
						layer.msg("角色信息获取失败");
					}
				});

				/*点击修改用户信息*/
				form.on('submit(btnaddadminuser)', function(pardata) {
					var adminuserid = $("#adminusername").val().trim();
					var pwd = $("#password").val();
					var confirmpwd = $("#confirmpassword").val().trim();
					var adminrealname = $("#adminrealname").val().trim();
					var phone = $("#phone").val().trim();
					var backrolemodel = $("#backrolemodel").val().trim();
					if(pwd != confirmpwd) {
						layer.msg("两次密码输入不一致");
						return;
					}
					
					/**
					 * 2019-1-7徐震霖修改添加
					 */
					if(pwd.length < 6 || pwd.length > 18){
						layer.msg('密码长度不符合规范!');
						return;
					}
					var enpwd = hex_md5(fix(Encryption_key,pwd));
					$("#password").val(enpwd);
					$("#confirmpassword").val(enpwd);
					
					if(backrolemodel == null || backrolemodel == "" || backrolemodel == 00 || backrolemodel == 'null') {
						layer.msg("请选择用户角色");
						return;
					}
					$.ajax({
						url: '../sysadminusermanager/addadminuser?userid=' + adminuserid + "&pwd=" + enpwd + "&mobile=" + phone + "&realname=" + adminrealname + "&roleId=" + backrolemodel,
						type: 'get',
						dataType: 'json',
						success: function(data) {
							if(data.code == 10001) {
								layer.confirm(data.msg, {
									btn: ['确定']
								}, function() {
									window.location.href = "../backAdminUserManagement/editAdminUser.jsp";
								});

							} else {
								layer.alert(data.msg, {
									icon: 2
								});
								return false;
							}
						}
					});
				});

			});
		</script>
	</body>

</html>